﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：马毅
    //
    // 文件名：ProductCompany.cs
    // 文件功能描述：查看产品配送企业
    // 创建标识：马毅2009-05-12
    //
    // 修改标识： 
    // 修改描述： 
    //
    // 修改标识： 
    // 修改描述： 
    //
    // 审核人： 
    // 审核时间： 
    // 审核说明： 
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
namespace HZ.DrugTrade.Web.Enterprise.RelationQuery
{
    public partial class ProductCompany : BasePage
    {
        public ProductCompany()
        { }

        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        protected void Page_Load(object sender, EventArgs e)
        {
            //绑定采购产品信息
            if (!IsPostBack)
            {
                string procureCatalogId = Request.QueryString["ProcureCatalogID"];
                HZ.DrugTrade.Model.View.ProcureCatalog procureCatalog = ipb.GetProcureCatalogByID(procureCatalogId);
                if (procureCatalog != null)
                {
                    txtGoodsName.Text = procureCatalog.GoodsName;
                    txtCompany_SC.Text = procureCatalog.CompanyName_SC;
                    txtCompany_TB.Text = procureCatalog.CompanyName_TB;
                    txtProcurePrice.Text = procureCatalog.ProcurePrice.ToString();
                 
                    txtProject.Text = procureCatalog.ProjectName;
                    if (procureCatalog.SortSource == 0)
                    {
                        txtSortSource.Text = "正常添加";
                    }
                    else if (procureCatalog.SortSource == 1)
                    {
                        //txtSortSource.Text = "临时采购";
                        txtSortSource.Text = "备案采购";
                    }
                    companyId.Value = procureCatalog.CompanyIDs_PS;
                    //companyName.Value = procureCatalog.CompanyNames_PS;
                    hfdCompanyName.Value = procureCatalog.CompanyNames_PS;

                    //将配送企业放入listbox中
                    string companyName = procureCatalog.CompanyNames_PS;
                    string companyID = procureCatalog.CompanyIDs_PS;
                    string[] arrayNames = companyName.Split(',');
                    string[] arrayIds = companyID.Split(',');
                    for (int i = 0; i < arrayNames.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(arrayNames[i]))
                        {
                            ListItem myItem = new ListItem();
                            myItem.Text = arrayNames[i];
                            myItem.Value = arrayIds[i];
                            lstCompanyName.Items.Add(myItem);
                        }
                    }
                }
                else
                {
                    PageError("采购产品不存在！", this.ReturnUrl);
                }
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            ProcureCatalog procureCatalog = new ProcureCatalog();
            procureCatalog.ProcureCatalogID = Request.QueryString["ProcureCatalogID"];
            procureCatalog.CompanyIDs_PS = companyId.Value.TrimEnd(',');
            procureCatalog.CompanyNames_PS = hfdCompanyName.Value.TrimEnd(',');

            if (ipb.UpdateProcureCatalog_CompanyPS(procureCatalog) == 1)
            {
                PageInfo("更新成功！", "ProductList.aspx");
            }
            else
            {
                PageError("更新失败！", "");
            }
        }
    }
}
